package io.xxx.walle.room;

import io.xxx.walle.room.api.JoinRoomRequest;
import io.xxx.walle.room.api.LeaveRoomRequest;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

@RestController
@RequestMapping("/room")
public class RoomController {

    @Resource
    private RoomService roomService;

    @Resource
    private RoomRepository roomRepository;

    /**
     * 入群
     */
    @PostMapping("/join")
    public void joinRoom(@RequestBody JoinRoomRequest request) {
        roomService.joinRoom(request);
    }

    /**
     * 退群
     */
    @PostMapping("/leave")
    public void leaveRoom(@RequestBody LeaveRoomRequest request) {
        roomService.leaveRoom(request);
    }

    /**
     * 获取群信息
     */
    @GetMapping("/{id}")
    public Optional<Room> get(@PathVariable Long id) {
        return roomRepository.findById(id);
    }
}
